<?php
/**
 * 注册控制器
 * */

class RegisterAction extends Action {
    public function index() {
        if (logined()) {
            $this->success('已登录', U('Index/index'));
        }

        if ($this->isPost()) {

            $this->email = $this->_post('email');
            $this->password = $this->_post('password');
            $this->password2 = $this->_post('password2');

            $Model = D('Member');
            if ($Model->create()) {
                if ( $Model->add() ) {
                    $this->user = D('Member')->where(array(
                        'email' => $this->email))->relation(true)->find();
                    $_SESSION['user'] = $this->user;
                    $this->success('注册成功，请等待审核...', U('Index/index'));
                }
                else {
                    $this->error_msg = "服务器尽力去注册您的用户，但还是失败了";
                    $this->display();
                }

            }
            else {
                $this->display();
            }
        } else {
            $this->display();
        }
    }

}
